package chapter03;

public class Test08_Static {
    public static void main(String[] args) {
        //静态成员出现的时间 在类加载的时候就出现了
        System.out.println(MoonCake.getCount());
        MoonCake c1 = new MoonCake(4,"五仁馅");
        //全局量使用类名获得
        MoonCake.addCount();
        c1.info();
        MoonCake c2 = new MoonCake(4,"椰蓉馅");
        MoonCake.addCount();
        c2.info();
        System.out.println(MoonCake.getCount());
    }
}
class MoonCake{
    private int size;
    private String filling;
    //计数器 用于统计生产了多少月饼 应该是一个全局数字 就要加上关键字static
    private static int count;
    public MoonCake(int size,String filling){
        this.size = size;
        this.filling = filling;
    }
    //使用静态函数操作静态成员
    static public void addCount(){
        count++;
    }
    static public int getCount(){
        return count;
    }
    public void info(){
        System.out.println(size);
        System.out.println(filling);
        System.out.println(count);
    }
}
